__CreateJSPath = function (js) {
    var scripts = document.getElementsByTagName("script");
    var path = "";
    for (var i = 0, l = scripts.length; i < l; i++) {
        var src = scripts[i].src;
        if (src.indexOf(js) != -1) {
            var ss = src.split(js);
            path = ss[0];
            break;
        }
    }
    var href = location.href;
    href = href.split("#")[0];
    href = href.split("?")[0];
    var ss = href.split("/");
    ss.length = ss.length - 1;
    href = ss.join("/");
    if (path.indexOf("http:") == -1 && path.indexOf("file:") == -1) {
        path = href + "/" + path;
    }
    return path;
}
var bootPATH = __CreateJSPath("login.js");
document.write('<script type="text/javascript" src="'+bootPATH+'../dataSource.js"></script>');

//登录界面
function loginPage(){
	$("input").keydown(function(){ 
		event.keyCode==13 && $("#frm_Sub").click();
	});
	$("#imgbutton").click(function() {
		loadImageCode();
	});
}

//加载验证码
function loadImageCode(){
	//$("#imgbutton").prev().attr("src","ImageCode?time=" + new Date().getTime());
	$("#ImageCode").attr("src","ImageCode?time=" + new Date().getTime());
}

//登录
function submitForm() {
	if (Valid()) {
		// 提交form表单，可避免jquery ajax提交出现中文乱码的问题
		$.post("AdminLogin", $("#loginForm").serialize(), function(text) {
			var data = (new Function("return "+text))();
			if (data.status=='登录成功') {
				location.href='index.jsp';
			}else{
				alert(data.status);
				loadImageCode();
			}
		});
	}
}
//清除信息
function clearForm() {
	$('#loginForm').form('clear');
}
//验证信息
function Valid() {
	var uname = $('#uname').val();
	uname = $.trim(uname);
	var pwd = $('#pwd').val();
	pwd = $.trim(pwd);
	var number = $('#number').val();
	number = $.trim(number);

	if (uname < 1) {
		$('#uname').focus();
		alert("请输入用户名！");
		return false;
	} else if (pwd.length < 1) {
		$('#pwd').focus();
		alert("请输入密码！");
		return false;
	} else if (number.length < 1) {
		$('#number').focus();
		alert("请输入验证码！");
		return false;
	} else
		return true;
}

$(document).ready(function(){ 
	loadSysInfo();
	loginPage();
});